<?php

namespace App\Admin\Controllers;

use \App\Models\QdcsOrg;

use com_jjcbs\lib\ServiceFactory;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use ext\service\OrgServiceImpl;

class OrgController extends Controller
{
    use ModelForm;


    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('慈善机构管理');
            $content->description('机构列表');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('慈善机构管理');
            $content->description('编辑');
            $content->disablePjax(true);

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('慈善机构管理');
            $content->description('创建');
            $content->disablePjax(true);

            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(QdcsOrg::class, function (Grid $grid) {

            $grid->id('ID')->sortable();
            $grid->name('机构名称');
            $grid->competent_org('主管单位');
            $grid->reg_number('登记号');
            $grid->org_number('组织机构代码');
            $grid->open_time('成立时间');
            $grid->created_at('新增时间');
            $grid->updated_at('编辑时间');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(QdcsOrg::class, function (Form $form) {

            $form->display('id', 'ID');
            $form->text('name','机构名称')->rules('required');
            $form->text('competent_org' , '主管单位(填0时表示一级机构)')->rules('required');
            $form->text('reg_number','登记号')->rules('required');
            $form->text('org_number','组织机构代码')->rules('required');
            $form->date('open_time','成立时间')->rules('required');
            $form->ueditor('longitude' , '地图位置（请使用百度地图插入并调整显示尺寸）');
            $form->display('created_at', '创建时间');
            $form->display('updated_at', '编辑时间');
        });
    }
}
